clear
set more off
cd "/Users/shahbanoijaz/Political Violence/data"

use master_dy_panel.dta

g running2002= year - 2001.5

g running1990 = year - 1990.5

capture log close

log using rd_graphs, replace

**Checking the probability of treatment (cutoff 2002) 
capture drop treat
g treat=1 if laid2>0
replace treat=0 if laid2==0 

capture drop below_c
g below_c=1 if year<2002
replace below_c=0 if year>=2002

capture drop below_cXrunning2002
g below_cXrunning2002 = below_c*running2002

reg treat below_c running2002 below_cXrunning2002, cluster(year) 
capture drop xb
predict xb

twoway scatter xb running2002, msize(small) xline(0) scheme(s1color) ytitle("Probability of Treatment") xtitle("Year - 2002.5") title("Validity of RD- 2002")
graph save validity1, replace

**Checking probability of treatment (cutoff 1990)
capture drop treat2 
g treat2=1 if laid2>0
replace treat2=0 if laid2==0 

capture drop below_c90
g below_c90=1 if year<1990.5
replace below_c90=0 if year>=1990.5

capture drop below_c90Xrunning1990
g below_c90Xrunning1990 = below_c90*running1990

reg treat2 below_c90 running1990 below_c90Xrunning1990, cluster(year)

capture drop xb
predict xb

twoway scatter xb running1990, msize(small) xline(0) scheme(s1color) ytitle("Probability of Treatment") xtitle("Year-1990.5") title("Validity of RD-1990")
graph save validity2, replace

graph combine validity1.gph validity2.gph, saving("/Users/shahbanoijaz/Political Violence/writing/validityrd.jpg")

**Creating outcome versus running for different bin-widths 

g levent = log(eventocc +1) 

twoway (scatter levent running2002, mcolor(gs10) msize(tiny))(lpolyci levent running2002 if running2002<0, bw(2) deg(5) n(1000) fcolor(none))(lpolyci levent running2002 if running2002>=0, bw(2) deg(5) n(1000) fcolor(none)), xtitle("Year - 2002.5") ytitle("Log (Incidents of Political Violence") xline(0)  legend(off) saving(rd2002_bw2.jpg, replace)

twoway (scatter levent running2002, mcolor(gs10) msize(tiny))(lpolyci levent running2002 if running2002<0, bw(3) deg(5) n(1000) fcolor(none))(lpolyci levent running2002 if running2002>=0, bw(3) deg(5) n(1000) fcolor(none)), xtitle("Year - 2002.5") ytitle("Log (Incidents of Political Violence") xline(0)  legend(off) saving(rd2002_bw3.jpg,replace)

twoway (scatter levent running2002, mcolor(gs10) msize(tiny))(lpolyci levent running2002 if running2002<0, bw(4) deg(5) n(1000) fcolor(none))(lpolyci levent running2002 if running2002>=0, bw(4) deg(5) n(1000) fcolor(none)), xtitle("Year - 2002.5") ytitle("Log (Incidents of Political Violence") xline(0)  legend(off) saving(rd2002_bw4.jpg, replace)


**For 1990 cutoff

twoway (scatter levent running1990, mcolor(gs10) msize(tiny))(lpolyci levent running1990 if running1990<0, bw(2) deg(5) n(1000) fcolor(none))(lpolyci levent running1990 if running1990>=0, bw(2) deg(5) n(1000) fcolor(none)), xline(0) xtitle("1990.5 - Year") ytitle("Log (Incidents of Political Violence")  legend(off) xsc(r(-20 10)) saving(rd1990_bw2.jpg, replace)

twoway (scatter levent running1990, mcolor(gs10) msize(tiny))(lpolyci levent running1990 if running1990<0, bw(3) deg(5) n(1000) fcolor(none))(lpolyci levent running1990 if running1990>=0, bw(3) deg(5) n(1000) fcolor(none)), xline(0)  xtitle("1990.5 - Year") ytitle("Log (Incidents of Political Violence") legend(off) xsc(r(-20 10)) saving(rd1990_bw3.jpg, replace)

twoway (scatter levent running1990, mcolor(gs10) msize(tiny))(lpolyci levent running1990 if running1990<0, bw(4) deg(5) n(1000) fcolor(none))(lpolyci levent running1990 if running1990>=0, bw(4) deg(5) n(1000) fcolor(none)), xline(0) xtitle("1990.5 - Year") ytitle("Log (Incidents of Political Violence") legend(off) xsc(r(-20 10)) saving(rd1990_bw4.jpg, replace)

**For Pooled Analysis
clear
use datapooled.dta 
g levent=log(eventocc +1) 

twoway (scatter levent running_pooled, mcolor(gs10) msize(tiny))(lpolyci levent running_pooled if running_pooled<0, bw(2) deg(5) n(1000) fcolor(none))(lpolyci levent running_pooled if running_pooled>=0, bw(2) deg(5) n(1000) fcolor(none)), xtitle("Pooled Running Variable") ytitle("Log (Incidents of Political Violence") xline(0)  legend(off) saving(rdpooled_bw2.jpg, replace)

twoway (scatter levent running_pooled, mcolor(gs10) msize(tiny))(lpolyci levent running_pooled if running_pooled<0, bw(3) deg(5) n(1000) fcolor(none))(lpolyci levent running_pooled if running_pooled>=0, bw(3) deg(5) n(1000) fcolor(none)), xtitle("Pooled Running Variabe") ytitle("Log (Incidents of Political Violence") xline(0)  legend(off) saving(rdpooled_bw3.jpg,replace)

twoway (scatter levent running_pooled, mcolor(gs10) msize(tiny))(lpolyci levent running_pooled if running_pooled<0, bw(4) deg(5) n(1000) fcolor(none))(lpolyci levent running_pooled if running_pooled>=0, bw(4) deg(5) n(1000) fcolor(none)), xtitle("Pooled Running Variable") ytitle("Log (Incidents of Political Violence") xline(0)  legend(off) saving(rdpooled_bw4.jpg, replace)
